package com.zzy.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzy.commonutils.R;
import com.zzy.edu.entity.EduCourse;
import com.zzy.edu.entity.EduTeacher;
import com.zzy.edu.service.EduCourseService;
import com.zzy.edu.service.EduTeacherService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author KAZU
 * @Date 2023/1/18 12:43
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

	@Autowired
	private EduCourseService courseService;
	
	@Autowired
	private EduTeacherService teacherService;
	
	@ApiOperation(value = "查询前八条热门课程，查询前四条名师")
	@GetMapping("index")
	public R index() {
		// 查询前八条热门课程
		QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
		courseQueryWrapper.orderByDesc("id");
		courseQueryWrapper.last("limit 8");
		List<EduCourse> courseList = courseService.list(courseQueryWrapper);
		// 查询前四条名师
		QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
		teacherQueryWrapper.orderByDesc("id");
		teacherQueryWrapper.last("limit 4");
		List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);
		return R.ok().data("courseList", courseList).data("teacherList", teacherList);
	}

}





